package com.cdd.goods.controller;


import com.cdd.goods.service.IGoodsService;

import com.common.entity.Goods;
import com.common.untils.CommonResult;

import com.common.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzl
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/goods/goods")
public class GoodsController {
    @Autowired
    private IGoodsService iGoodsService;
    @PostMapping ("/selectgoods/{currentPage}/{pageSize}")
    public CommonResult selectgoods(@PathVariable Integer currentPage,@PathVariable Integer pageSize,@RequestBody Map map){
        return  iGoodsService.selectAll(currentPage,pageSize,map);
    }
    @PostMapping ("/selectGoodsZone")
    public  List<GoodsVo> selectGoodsZone(){
        return  iGoodsService.selectGoodsZone();
    }
    //上传头像
//    @RequestMapping("/upload")
//    public CommonResult upload(MultipartFile file){
//        String path = OSSUtils.upload(file);
//        System.out.println("++++++"+path);
//        return new CommonResult(2000,"上传成功",path);
//    }
    @GetMapping("/deletegoods/{id}")
    public CommonResult deletegoods(@PathVariable String id){
        return iGoodsService.deletegoods(id);
    }
    //    商品信息页面添加按钮方法
@PostMapping("/insert")
    public CommonResult insert(@RequestBody GoodsVo goodsVo){
        return iGoodsService.insert(goodsVo);
        }
  @PostMapping("/update")
    public CommonResult update(@RequestBody Goods goods){
      System.out.println(goods+"-------------------------");
        return  iGoodsService.update(goods);
  }
  @PostMapping("findAll/{currentPage}/{pageSize}")
    public CommonResult findAll(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        return iGoodsService.findAll(currentPage,pageSize);
  }
  @PostMapping("collect/{zid}/{sid}")
    public CommonResult collect(@PathVariable Integer zid, @PathVariable Integer sid, HttpServletRequest request){
      String homeToken = request.getHeader("homeToken");
      return iGoodsService.collect(zid,sid,homeToken);
  }
  @PostMapping("qxcollect/{zid}/{sid}")
    public CommonResult qxcollect(@PathVariable Integer zid,@PathVariable Integer sid){
        return iGoodsService.qxcollect(zid,sid);
  }
      @PostMapping("findAllCollect")
        public CommonResult findAllCollect(@RequestBody com.cdd.goods.vo.GoodsVo goodsVo,HttpServletRequest request){
          String homeToken = request.getHeader("homeToken");
         return iGoodsService.findAllCollect(goodsVo,homeToken);
      }
      @PostMapping("findByShopIdCollect/{shopid}/{goodsid}")
    public CommonResult findByShopIdCollect(@PathVariable String shopid,@PathVariable String goodsid,HttpServletRequest request){
          String homeToken = request.getHeader("homeToken");
          return iGoodsService.findByShopIdCollect(shopid,goodsid,homeToken);
      }

    }
